﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <input type="hidden" id="id" name="id" />
        <div class="form-group">
            <label class="col-sm-2 control-label ">登录名称<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="userName" name="userName" autocomplete="off" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">登录密码<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="password" name="password" type="password" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">姓名</label>
            <div class="col-sm-4">
                <input id="realName" name="realName" autocomplete="off" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">性别</label>
            <div class="col-sm-4" id="gender" name="gender"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">生日</label>
            <div class="col-sm-4">
                <input id="birthday" name="birthday" autocomplete="off" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">部门</label>
            <div class="col-sm-4">
                <div id="departmentId" name="departmentId"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">手机</label>
            <div class="col-sm-4">
                <input id="mobile" name="mobile" autocomplete="off" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">职位</label>
            <div class="col-sm-4">
                <div id="positionIds" name="positionIds"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">邮箱</label>
            <div class="col-sm-4">
                <input id="email" name="email" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label">状态</label>
            <div class="col-sm-4" id="userStatus" name="userStatus"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">角色</label>
            <div class="col-sm-10" id="roleIds" name="roleIds"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">备注</label>
            <div class="col-sm-10">
                <textarea id="remark" name="remark" class="form-control" style="height:60px"></textarea>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        //加载用户状态
        $("#userStatus").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(StatusEnum).EnumToDictionaryString())) });
        //加载性别
        $("#gender").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(YiSha.Enums.OrganizationManage.GenderTypeEnum).EnumToDictionaryString())) });
        //查询角色信息
        $("#roleIds").ysCheckBox({
            url: '/SystemManage/Role/GetListJson',
            key: "id",
            value: "roleName"
        });
        //查询职位
        $("#positionIds").ysComboBox({
            url: '/OrganizationManage/Position/GetListJson',
            key: "id",
            value: "positionName",
            class: "form-control",
            multiple: true
        });
        //查询部门
        $('#departmentId').ysComboBoxTree({
            url: '/organizationmanage/department/getdepartmenttreelistjson',
            callback: {
                onClick: function (treeNode) {
                }
            }
        });
        //初始时间
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            var startDate = laydate.render({
                elem: '#birthday',
                theme: 'molv',
                trigger: 'click',
            });
        });
        getForm();
        //提交数据校验
        $("#form").validate({
            ignore: ".ignore",
            rules: {
                userName: { required: true },
                password: {
                    required: true,
                    minlength: 6,
                    maxlength: 100
                },
                realName: { required: true },
                departmentId_input: { required: true },
                mobile: { required: true, isPhone: true},
                email: { email: true },
                positionIds_select: { required: true },
                roleIds_checkbox: { required: true}
            }
        });
    });

    //提交数据
    function submitForm(index) {
        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls();
            postData.DepartmentName = $('#departmentId').ysComboBoxTree("getText");
            postData.PositionName = $("#positionIds").ysComboBox("getText");
            postData.RoleName = $("#roleIds").ysCheckBox("getText");
            $.operate.save("/OrganizationManage/User/SaveFormJson", postData);
        }
    }
    function getForm() {
        //修改赋值使用
        var editData = storage.get("editData");
        if (editData != null && editData.length > 0) {
            editData.departmentId = editData.departmentIdAll;
            //表单赋值
            $("#form").setWebControls(JSON.parse(editData));
            //修改时禁用密码框
            $("#password").attr('disabled', 'disabled');
        } else {
            //界面初始化 给状态、性别赋值
            var defaultData = {};
            defaultData.gender = 1;
            defaultData.userStatus = 1;
            $("#form").setWebControls(defaultData);
        }
    }
</script>
